﻿using Abp.Application.Services.Dto;
using Abp.Web.Mvc.Authorization;
using MyCompanyName.AbpZeroTemplate.Persons;
using MyCompanyName.AbpZeroTemplate.Persons.Authorization;
using MyCompanyName.AbpZeroTemplate.Persons.Dtos;
using MyCompanyName.AbpZeroTemplate.Web.Areas.Mpa.Models.PersonManage;
using MyCompanyName.AbpZeroTemplate.Web.Controllers;
using System;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace MyCompanyName.AbpZeroTemplate.Web.Areas.Mpa.Controllers
{
    //[AbpMvcAuthorize(PersonAppPermissions.Person)]
    public class PersonManageController : AbpZeroTemplateControllerBase
    {
        private readonly IPersonAppService _personAppService;

        public PersonManageController(IPersonAppService personAppService)
        {
            _personAppService = personAppService;
        }

        public ActionResult Index()
        {
            var model = new GetPersonInput { FilterText = Request.QueryString["filterText"] };
            return View(model);
        }

        /// <summary>
        /// 根据id获取进行编辑或者添加的用户信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [AbpMvcAuthorize(PersonAppPermissions.Person_CreatePerson, PersonAppPermissions.Person_EditPerson)]
        public async Task<PartialViewResult> CreateOrEditPersonModal(int? id)
        {
            var input = new NullableIdDto<int> { Id = id };
            var output = await _personAppService.GetPersonForEditAsync(input);
            var viewModel = new CreateOrEditPersonModalViewModel(output);

            return PartialView("_CreateOrEditPersonModal", viewModel);
        }
    }
}